<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 分割数组 -->
    <script>
      var partitionDisjoint = function (nums) {
        const n = nums.length
        const minRight = new Array(n).fill(0)
        minRight[n - 1] = nums[n - 1]
        for (let i = n - 2; i >= 0; i--) {
          minRight[i] = Math.min(nums[i], minRight[i + 1])
        }

        let maxLeft = 0
        for (let i = 0; i < n - 1; i++) {
          maxLeft = Math.max(maxLeft, nums[i])
          if (maxLeft <= minRight[i + 1]) {
            return i + 1
          }
        }
        return n - 1
      }
      console.log(partitionDisjoint([5, 0, 3, 8, 6]))
    </script>
  </body>
</html>
